package com.mentaleye.biz.impl;

import com.mentaleye.bean.CompanyStudentBean;
import com.mentaleye.bean.StudentsBean;
import com.mentaleye.biz.CompanyStudentBiz;
import com.mentaleye.service.CompanyStudentService;
import com.mentaleye.util.CommonResult;
import org.apache.log4j.Logger;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.Map;

/**
 * Created by Rock on 2017/5/19.
 */
@Service
public class CompanyStudentBizImpl implements CompanyStudentBiz {

    private static Logger logger = Logger.getLogger(CompanyStudentBizImpl.class);

    @Autowired private CompanyStudentService companyStudentService;

    public CommonResult edit(CompanyStudentBean bean, boolean isAdd){
        CommonResult result = new CommonResult();
        boolean success = false;
        try {
            if (isAdd){
                success = companyStudentService.add(bean);
            }else{
                success = companyStudentService.updateByReturnVisitId(bean);
            }
            result.setIsSuccess(success);
        }catch (Exception e){
            logger.error("编辑企业学生异常",e);
        }
        return result;
    }

    public CommonResult update(CompanyStudentBean bean){
        CommonResult result = new CommonResult();
        boolean success = false;
        try {
            success = companyStudentService.update(bean);
            result.setIsSuccess(success);
        }catch (Exception e){
            logger.error("修改企业学生状态异常",e);
        }
        return result;
    }

    public CommonResult removeList(List<Integer> returnVisitIds){
        CommonResult result = new CommonResult();
        boolean success = false;
        try {
            success = companyStudentService.removeList(returnVisitIds);
            result.setIsSuccess(success);
        }catch (Exception e){
            logger.error("批量删除企业学生状态异常",e);
        }
        return result;
    }

    public List<StudentsBean> queryByState(Integer state, Integer workState){
        try{
            return companyStudentService.queryByState(state,workState);
        }catch (Exception e){
            logger.error("根据学生状态查询学生异常",e);
        }
        return null;
    }

    public Map<String, Object> queryDataByReturnVisitId(Integer returnVisitId){
        try{
            return companyStudentService.queryDataByReturnVisitId(returnVisitId);
        }catch (Exception e){
            logger.error("根据回访记录编号查询数据异常",e);
        }
        return null;
    }

    public List<Map<String, Object>> queryStudentByCompanyId(Integer comapnyId){
        try{
            return companyStudentService.queryStudentByCompanyId(comapnyId);
        }catch (Exception e){
            logger.error("根据企业编号查询学生数据异常",e);
        }
        return null;
    }
}
